﻿using Publicuse.Entity;
using Publicuse.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Publicuse.Cache
{
    public class CityCache
    {
        private static List<City> cities = new List<City>();

        /// <summary>
        /// 缓存省市区数据
        /// </summary>
        /// <param name="mySqlSugar"></param>
        public static void CacheCityData(IMySqlSugarService mySqlSugar)
        {
            if (cities.Count == 0)
            {
                mySqlSugar.Work(out var msg, db =>
                {
                    cities = db.Queryable<City>().ToList();
                }, false);
            }
        }

        /// <summary>
        /// 获取省市区数据
        /// </summary>
        /// <param name="mySqlSugar"></param>
        /// <returns></returns>
        public static List<City> GetCityData(IMySqlSugarService mySqlSugar)
        {
            if (cities.Count == 0)
            {
                mySqlSugar.Work(out var msg, db =>
                {
                    cities = db.Queryable<City>().ToList();
                }, false);
            }
            return cities;
        }
    }
}
